package com.qk.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @Author: zhangchuang
 * @Date: 2025/10/17 11:58
 * @Description: 时间消耗统计切面
 */
@Aspect
@Component
@Slf4j
public class TimeConsumeCountAOP {

    @Pointcut("execution(* com.qk.service.*.*(..))")
    public void servicePointcut() {}

    @Around("servicePointcut()")
    public Object TimeCountAround(ProceedingJoinPoint pjp) throws Throwable {
        long s = System.currentTimeMillis();
        Object res = pjp.proceed();
        long e = System.currentTimeMillis();
        String cName = pjp.getTarget().getClass().getSimpleName();
        String mName = pjp.getSignature().getName();

        log.info("{}类中{}方法耗时：{}ms", cName, mName, e - s);
        return res;
    }

}
